/* GUI CONVERTED from admgmt06.p (converter v1.76) Wed May 28 03:34:24 2003 */
/* admgmt06.p - COMPANY ADDRESS MAINTENANCE                                   */
/* Copyright 1986-2003 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.14.1.13 $                                              */
/* REVISION: 6.0      LAST MODIFIED: 10/09/90   BY: MLB *D083*                */
/*                                   12/27/90   BY: MLB *D238*                */
/*                                   08/09/91   BY: RAM *D820*                */
/* REVISION: 7.0      LAST MODIFIED: 09/17/91   BY: MLV *F015*                */
/*                                   11/16/91   BY: pml *F048*                */
/*                                   01/22/92   BY: afs *F040*                */
/*                                   04/09/92   BY: tjs *F337*                */
/*                                   06/30/92   BY: tjs *F698*                */
/* REVISION: 7.3      LAST MODIFIED: 09/27/92   BY: afs *G099*                */
/*                                   12/15/92   BY: bcm *G426*                */
/*                                   01/12/93   by: jms *G535*                */
/*                                   01/21/93   BY: afs *G580*                */
/*                                   02/23/93   by: bcm *G726*                */
/* REVISION: 7.4      LAST MODIFIED: 08/16/93   by: dpm *H075*                */
/*                                   10/07/93   by: bcm *H160*                */
/*                                   10/13/93   by: jjs *H181*                */
/*                                   12/01/93   by: bcm *H260*                */
/*                                   02/03/94   by: dpm *FL92*                */
/*                                   05/23/94   by: bcm *H373*                */
/*                                   06/20/94   by: rmh *FO78*                */
/*                                   07/18/94   by: pmf *GK77*                */
/*                                   09/11/94   by: slm *GM11*                */
/*                                   11/06/94   by: ljm *GO15*                */
/*                                   02/23/95   by: jzw *H0BM*                */
/*                                   03/10/95   by: srk *H0BN*                */
/*                                   04/18/95   by: jzw *H0CN*                */
/*                                   11/13/95   by: ais *G1D4*                */
/*                                   11/15/95   BY: rxm *H0GZ*                */
/*                                   12/20/95   BY: ame *F0WW*                */
/* REVISION: 8.6      LAST MODIFIED: 09/03/96   BY: jzw *K008*                */
/*                    LAST MODIFIED: 10/29/96   BY: jpm *K01J*                */
/* REVISION: 8.6      LAST MODIFIED: 10/31/96   BY: *H0N3* Suresh Nayak       */
/* REVISION: 8.6      LAST MODIFIED: 11/11/96   BY: *J17V* Suresh Nayak       */
/* REVISION: 8.6      LAST MODIFIED: 07/17/97   BY: *J1VT* Suresh Nayak       */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane          */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan         */
/* REVISION: 8.6E     LAST MODIFIED: 07/06/98   BY: *H1LP* Samir Bavkar       */
/* REVISION: 8.6E     LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan         */
/* REVISION: 9.0      LAST MODIFIED: 03/10/99   BY: *M0B3* Michael Amaladhas  */
/* REVISION: 9.0      LAST MODIFIED: 03/13/99   BY: *M0BD* Alfred Tan         */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane   */
/* REVISION: 9.1      LAST MODIFIED: 08/11/00   BY: *N0KK* jyn                */
/* REVISION: 9.1      LAST MODIFIED: 10/18/00   BY: *N0VR* BalbeerS Rajput    */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* Revision: 1.14.1.7       BY: Katie Hilbert     DATE: 04/01/01  ECO: *P002* */
/* Revision: 1.14.1.8       BY: Chris Green       DATE: 02/05/02  ECO: *N16J* */
/* Revision: 1.14.1.9       BY: Jean Miller       DATE: 05/22/02  ECO: *P074* */
/* Revision: 1.14.1.10      BY: Paul Donnelly     DATE: 06/14/02  ECO: *M1ZL* */
/* Revision: 1.14.1.11      BY: Rajaneesh S.      DATE: 02/14/03  ECO: *N27G* */
/* Revision: 1.14.1.12      BY: Narathip W.       DATE: 04/17/03  ECO: *P0Q4* */
/* $Revision: 1.14.1.13 $    BY: Ed van de Gevel     DATE: 05/28/03  ECO: *N2FD* */
/* $Revision: eb2 sp3 $    BY: Joy Huang          DATE: 11/11/03  ECO: *HK-S-017*  */

/*V8:ConvertMode=Maintenance                                                  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

{mfdtitle.i "2+ "}
{pxpgmmgr.i}
{pxsevcon.i}
{cxcustom.i "ADMGMT06.P"}

define new shared variable undo_adtaxmt as logical.
define new shared variable promo_old like cm_promo.

define shared variable name like ad_name.

define variable badField as character no-undo.
define variable del-yn like mfc_logical.
define variable type like ls_type initial "company".
define variable msg-arg as character format "x(16)" no-undo.

/* VARIABLES FOR VAT REGISTRATION VALIDATION */
{gpvtevdf.i "new shared"}

find first gl_ctrl no-lock no-error.

do transaction on error undo, retry:
   find first adc_ctrl no-lock no-error.
   if not available adc_ctrl then create adc_ctrl.
   if recid(adc_ctrl) = -1 then.
end.

/* DISPLAY SELECTION FORM */
{&ADMGMT06-P-TAG2}

/*GUI preprocessor Frame A define */
&SCOPED-DEFINE PP_FRAME_NAME A

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1.4 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1   COLUMN 3 NO-LABEL
 SKIP(.1)  /*GUI*/

   ls_addr         colon 12
   ad_name         colon 12
   ad_line1        colon 12
   ad_line2        colon 12
   ad_line3        colon 12
   ad_city         colon 12
   ad_state
   ad_zip
   ad_format
   ad_country      colon 12
   ad_ctry         no-label
   ad_county       colon 56
   ad_attn         colon 12
   ad_attn2        label "[2]" colon 48
   ad_phone        colon 12
   ad_ext
   ad_phone2       label "[2]" colon 48
   ad_ext2
   ad_fax          colon 12
   ad_fax2         label "[2]" colon 48
   ad_tax_report   colon 12 label "Tax Report"
   ad_name_control colon 48 label "Name Control"
   ad_last_file    colon 70 label "Last Filing"
 SKIP(.4)  /*GUI*/
with frame a 
side-labels width 80 NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-a-title AS CHARACTER.
 F-a-title = (getFrameTitle("COMPANY_ADDRESS",23)).
 RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
 RECT-FRAME-LABEL:WIDTH-PIXELS in frame a =
  FONT-TABLE:GET-TEXT-WIDTH-PIXELS(
  RECT-FRAME-LABEL:SCREEN-VALUE in frame a + " ", RECT-FRAME-LABEL:FONT).
 RECT-FRAME:HEIGHT-PIXELS in frame a =
  FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME a = FRAME a:WIDTH-CHARS - .5. /*GUI*/

/*GUI preprocessor Frame A undefine */
&UNDEFINE PP_FRAME_NAME


{&ADMGMT06-P-TAG3}

/* SET EXTERNAL LABELS */
setFrameLabels(frame a:handle).

/* DISPLAY */
mainloop:
repeat:
/*GUI*/ if global-beam-me-up then undo, leave.


   view frame a.

   do transaction with frame a on endkey undo, leave mainloop:
/*GUI*/ if global-beam-me-up then undo, leave.


      hide frame setb2_sub no-pause.
      hide frame seta_sub no-pause.
      view frame a.

      prompt-for
         ls_mstr.ls_addr
      editing:

         /* FIND NEXT/PREVIOUS RECORD */
         {mfnp01.i ls_mstr ls_addr ls_addr type ls_type ls_type}

         if recno <> ? then do:
            find ad_mstr where ad_addr = ls_addr no-lock no-error.
            display
               ls_addr ad_name ad_line1 ad_line2 ad_line3 ad_city
               ad_state ad_zip ad_format ad_country
               ad_ctry ad_county
               ad_attn ad_phone ad_ext
               ad_fax ad_attn2 ad_phone2 ad_ext2 ad_fax2
           ad_tax_report ad_name_control ad_last_file.
         end.

      end.

      if input ls_mstr.ls_addr = "" then do:
         /* Blank not allowed */
         {pxmsg.i &MSGNUM=40 &ERRORLEVEL=3}
         undo, retry.
      end.

/*hk-s-017*/        if (can-find(sp_mstr where input ls_addr = sp_addr no-lock)
	             or can-find(cm_mstr where input ls_addr = cm_addr no-lock)
	             or can-find(vd_mstr where input ls_addr = vd_addr no-lock))
	            then undo,retry.  

      /* ADD/MOD/DELETE  */
      find ad_mstr where ad_addr = input ls_addr
      exclusive-lock no-error.

      if not available ad_mstr then do:
         create ad_mstr.
         assign
            ad_addr = input ls_addr
            ad_date = today
            ad_format = adc_format
            ad_type = type
            ad_taxable = yes.
            {&ADMGMT06-P-TAG1}
         if recid(ad_mstr) = -1 then.
      end.

      /* STORE MODIFY DATE AND USERID */
      ad_mod_date = today.
      ad_userid = global_userid.

      find ls_mstr where ls_addr = ad_addr and ls_type = type
      exclusive-lock no-error.

      if not available ls_mstr then do:
         /* Adding new record */
         {pxmsg.i &MSGNUM=1 &ERRORLEVEL=1}
         create ls_mstr.
         assign
            ls_addr = ad_addr
            ls_type = type.
         if recid(ls_mstr) = -1 then.
      end.

      del-yn = no.
      recno = recid(ls_mstr).

      display
         ad_name ad_line1 ad_line2 ad_line3
         ad_city ad_state ad_zip ad_format
         ad_country
         ad_ctry
         ad_county ad_attn ad_phone
         ad_ext ad_fax ad_attn2 ad_phone2 ad_ext2 ad_fax2
         ad_tax_report ad_name_control ad_last_file
      with frame a.

      set1:
      do on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.


         display ad_country.

         set
            ad_name ad_line1 ad_line2
            ad_line3 ad_city ad_state ad_zip ad_format
            ad_ctry
            ad_county
            ad_attn ad_phone ad_ext ad_fax ad_attn2 ad_phone2 ad_ext2
            ad_fax2
            ad_tax_report ad_name_control ad_last_file
         editing:

            ststatus = stline[2].
            status input ststatus.
            readkey.

            /* DELETE */
            if lastkey = keycode("F5") or lastkey = keycode("CTRL-D")
            then do:
               del-yn = yes.
               /* Please confirm delete */
               {pxmsg.i &MSGNUM=11 &ERRORLEVEL=1 &CONFIRM=del-yn}
               if del-yn then leave set1.
            end.
            else
               apply lastkey.
         end.

         if input ad_format <> 0 then do:
            find first code_mstr where code_fldname = "ad_format"
                                   and code_value = string(input ad_format)
            no-lock no-error.
            if not available code_mstr then do:
               /* Code does not exist in generalized codes */
               {pxmsg.i &MSGNUM=716 &ERRORLEVEL=4}
               next-prompt ad_format.
               undo.
            end.
         end.

         if not {gpctry.v ad_ctry ""no""} then do:
            {pxmsg.i &MSGNUM=861 &ERRORLEVEL=3}
            /* COUNTRY CODE DOES NOT EXIST */
            next-prompt ad_ctry with frame a.
            undo set1, retry.
         end.
         else do:
            find ctry_mstr where ctry_ctry_code = ad_ctry
            no-lock no-error.
            if available ctry_mstr then do:
               ad_country = ctry_country.
               display ad_country with frame a.
            end.
         end.

         if ad_tax_report = yes then do:

            validate ad_mstr.
            validate ls_mstr.

            if not (new ad_mstr) then do:
               /* CHECK THAT THIS IS ONLY A COMPANY ADDRESS.  */
               /* CANNOT USE THIS ADDRESS ON A 1099 REPORT IF */
               /* IT IS ALSO USED AS A SUPPLIER OR            */
               /* SHIP-TO OR ETC. */
               {pxrun.i &PROGRAM = 'adadxr.p'
                     &PROC = 'ValidateCompanyOnly'
                     &PARAM = "(input ad_addr)"
                     &CATCHERROR=true
                     &NOAPPERROR=true}
               if return-value <> {&SUCCESS-RESULT} then do:
                   next-prompt ad_tax_report with frame a.
                   undo set1, retry.
               end. /* return-value */
            end. /* if not (New ad_mstr) */

            {pxrun.i &PROGRAM = 'adadxr.p'
                     &PROC = 'ValidateTaxReport'
                     &PARAM = "(input ad_addr, output badField)"
                     &CATCHERROR=true
                     &NOAPPERROR=true}
             if return-value <> {&SUCCESS-RESULT} then do:
                 case badField:
                     when "ad_tax_report" then do:
                         next-prompt ad_tax_report with frame a.
                         undo set1, retry.
                     end.
                     when "ad_name" then do:
                         next-prompt ad_name with frame a.
                         undo set1, retry.
                     end.
                     when "ad_line1" then do:
                         next-prompt ad_line1 with frame a.
                         undo set1, retry.
                     end.
                     when "ad_city" then do:
                         next-prompt ad_city with frame a.
                         undo set1, retry.
                     end.
                     when "ad_state" then do:
                         next-prompt ad_state with frame a.
                         undo set1, retry.
                     end.
                     when "ad_zip" then do:
                         next-prompt ad_zip with frame a.
                         undo set1, retry.
                     end.
                     when "ad_phone" then do:
                         next-prompt ad_phone with frame a.
                         undo set1, retry.
                     end.
                     when "ad_name_control" then do:
                         if not batchrun then
                             pause.
                     end.
                     otherwise do:
                         next-prompt ad_tax_report with frame a.
                         undo set1, retry.
                     end.
                 end case.


             end. /* return-value */

         end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* if ad_tax_report = yes */

         /* INPUT TAX DATA */
         undo_adtaxmt = true.
         {adtaxmt.i "undo_adtaxmt" "ad_mstr."}
         if undo_adtaxmt then
             undo set1, retry.

      end.
/*GUI*/ if global-beam-me-up then undo, leave.
  /*END SET1 */

      ad_sort = ad_name.

      if del-yn then do:

         /* CHECK FOR ENTITIES USING THIS ADDRESS */
         for first en_mstr
            fields (en_entity en_addr)
            where en_addr = ad_addr
         no-lock:
            /* Delete not allowed. # exists in # */
            msg-arg = getTermLabel("ENTITY",16).
            {pxmsg.i &MSGNUM=904 &ERRORLEVEL=3
                      &MSGARG1=ad_addr
                      &MSGARG2=msg-arg}
             undo mainloop, retry.
         end.

         /* CHECK FOR OPEN PURCHASE ORDERS */
         find first po_mstr where po_ship = ad_addr no-lock no-error.
         if available po_mstr then do:
            /* Delete not allowed, PO exists */
            {pxmsg.i &MSGNUM=310 &ERRORLEVEL=4 &MSGARG1=po_nbr}
            undo, retry.
         end.

         if can-find(first si_mstr
                        where si_site = ad_addr)
         then do:
            /* DELETE NOT ALLOWED. SITE EXISTS. */
            {pxmsg.i &MSGNUM=5956 &ERRORLEVEL=4}
            undo mainloop, retry mainloop.
         end. /* IF CAN-FIND(FIRST si_mstr...) */


         {&ADMGMT06-P-TAG4}


         /* Delete user maintained ls_mstr */
         {adlsdl.i ad_mstr "company"}

         /* DELETE LIST MASTER */
         find first ls_mstr where ls_addr = ad_addr and ls_type = type
         use-index ls_type exclusive-lock no-error.

         if available ls_mstr then delete ls_mstr.

         /* DELETE ADDRESS MASTER */
         find first ls_mstr where ls_addr = ad_addr no-lock no-error.

         if not available ls_mstr then do:

            /* DELETE EDI SHIP IDs FOR THIS ADDRESS */
            {gprun.i ""gpsfiddl.p"" "(input ad_addr)"}
/*GUI*/ if global-beam-me-up then undo, leave.


            /* DELETE BANK DETAIL RECORDS(csbd_det) IF THEY  */
            /* AREN'T BEING UTILIZED BY ANOTHER ADDRESS TYPE */
            /* OF THIS ADDRESS.                              */
            {gprun.i 'adcsbdd.p'
               "(input ad_mstr.ad_addr, input 'COMPANY')"}
/*GUI*/ if global-beam-me-up then undo, leave.


            delete ad_mstr.
         end.

         {pxmsg.i &MSGNUM=22 &ERRORLEVEL=1} /* Record deleted */
         clear all no-pause.
         next.

      end.
/*GUI*/ if global-beam-me-up then undo, leave.


   end. /* END LOOP A  */

   /* UPDATE BANK ACCOUNTS; WITH 2 FRAME ROWS AND NO VALIDATION */
   {gprun.i ""adcsbdmt.p""
      "(input recid(ad_mstr),
        input 2,
        input false)"}
/*GUI*/ if global-beam-me-up then undo, leave.


end. /* END MAIN LOOP */

/* THE FOLLOWING SECTION ALSO APPEARS IN mf.p */
name = "QAD".

do for ad_mstr:

   find ls_mstr where ls_addr = "~~screens" and ls_type = "company"
   no-lock no-error.

   if available ls_mstr then
      find ad_mstr where ad_addr = ls_addr
      no-lock no-error.

   if available ad_mstr then
      name = ad_name + " : " + if global_db <> "" then global_db
                               else sdbname("qaddb").
end.

status input.
